<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>矩形</title>
  <style>
    canvas {
      border: 1px solid #666;
    }
  </style>
</head>

<body>
  <canvas id="app" width="500" height="500"></canvas>
  <script>
    // 1.获取canvas画布
    var app = document.querySelector('canvas')
    // 2.获取上下文对象（画笔）
    var context = app.getContext('2d');
    // 3.绘制
    // 3.1设置绘制的样式
    context.fillStyle = 'teal';
    context.strokeStyle = 'orange'
    // 3.2执行绘制
    context.fillRect(10, 10, 300, 100)
    context.strokeRect(10, 120, 300, 100)
  </script>
</body>

</html>